package com.ifreshwing.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by lz on 2017/4/27.
 * 缓存配置数据
 */

public class SharedPreferencesUtil {
    private static final String USER_INFO = "user_info";
    private static final String IS_LOGIN = "is_login";

    /**
     * 存储用户登录状态
     * @param context
     * @param isLogin
     * */
    public  static void setIsLogin(Context context,boolean isLogin){
        if (context == null)
            return;
        SharedPreferences sp = context.getSharedPreferences(USER_INFO,
                Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(IS_LOGIN, isLogin);
        editor.apply();
    }

    /**
     * 获取用户登录状态
     * @param context
     * */
    public static boolean isLogin(Context context){
        if(context == null)
            return false;
        SharedPreferences sp = context.getSharedPreferences(USER_INFO,
                Activity.MODE_PRIVATE);
        return sp.getBoolean(IS_LOGIN, false);
    }
}
